<?php
function gglink($link){
return preg_replace('/https:\/\/(.*?)googleusercontent\.com/', 'http://3.bp.blogspot.com', $link);
}
function common_check_image($data){
$data = mb_convert_encoding($data, 'HTML-ENTITIES', "UTF-8"); 
$dom = new DOMDocument;
 $dom->loadHTML($data); 
 $sxe = simplexml_import_dom($dom);

	$j=0;	
	 foreach ($sxe->xpath('//img[@src]') as $a)
	 {	
		
		$j++;
	 }
 return $j;
}
 function common_picasa_remote($url,$type='manga'){
 													 if($url!=''){
														 $url_remote="http://up.manga24h.com/tct/upload_remote.php?link=$url&server=picasa&id=$type";
														 $data='';
														 $res= mycurl($data,$url_remote);
														
														 $res=json_decode($res,true);
														
															if($res['error']==false &&$res['url']!=''){
																
																return $res['url'];
															}else{
																//Doupload lan 2
																 sleep(2);
																 $url_remote="http://up.manga24h.com/tct/tct_upload.php?link=$url&server=picasa&id=$type";
																 $res= mycurl($data,$url_remote);
																 				
																 $res=json_decode($res,true);
																if($res['error']==false&&$res['url']!=''){
																		return $res['url'];
																
																}else{
																	return false;
																}
															}
													 }else{ //$URL !=''
													 	return false;
													 }
 }

 
function validate_string($str, $strTag){
	if($strTag){
		$strTagArray = explode(',', $strTag);
		foreach($strTagArray as $key => $value){
			$find = stripos($str, '<'.$value);
			if($find !== false){
				return false;
			}
		}
		
		return true;
	}
	
	return true;
}

function strip_tags_attributes( $str,
		$allowedTags = array('<b>','<i>','<blockquote>','<br>','<cite>','<code>','<del>','<em>','<ul>','<ol>','<li>','<dl>','<dt>','<dd>','<img>','<ins>','<u>','<q>','<h3>','<h4>','<h5>','<h6>','<samp>','<strong>','<sub>','<sup>','<p>','<table>','<tr>','<td>','<th>','<pre>','<span>'),
		$disabledEvents = array('iframe','a', 'id','style','onclick','ondblclick','onkeydown','onkeypress','onkeyup','onload','onmousedown','onmousemove','onmouseout','onmouseover','onmouseup','onunload') )
{
	if( empty($disabledEvents) ) {
		return strip_tags($str, implode('', $allowedTags));
	}
	return preg_replace('/<(.*?)>/ies', "'<' . preg_replace(array('/javascript:[^\"\']*/i', '/(" . implode('|', $disabledEvents) . ")=[\"\'][^\"\']*[\"\']/i', '/\s+/'), array('', '', ' '), stripslashes('\\1')) . '>'", strip_tags($str, implode('', $allowedTags)));
}


function common_static_admin(){
	//--------------MANGA------------------
	//			--Admin có tất car persmission
	//			--Smod,Uploader được duyệt truyện và fix chap
						if(isset($_SESSION['user'])&&($_SESSION['user']['level']==1||$_SESSION['user']['level']==2||$_SESSION['user']['level']==5||$_SESSION['user']['level']==6)){
		
						$cache=new cache;
						$dt=$cache->load('static','home');
						if(!$dt){
							//Count số cẫn xử lý
						$admin=0;
						$smod=0;
						$uploader=0;
						$db=new db;
						$db->connect();
								//-----Duyet Anime
						$db->query("select id from anime where duyet=0");
						$dt['duyet_anime']= $db->num_rows();
						$admin=$admin+$dt['duyet_anime'];
						$smod=$smod+$dt['duyet_anime'];
								//-----Xoa anime
						$db->query("select id from anime where xoa=1");
						$dt['xoa_anime']=$db->num_rows();
						$admin=$admin+$dt['xoa_anime'];
						//DUYET VA XOA FANSUB
						//XOA EPISODE
						
						$db->query("select id from chapterk2 where xoa=1");
						$dt['xoa_episode']=$db->num_rows();
						$admin=$admin+$dt['xoa_episode'];
						$smod=$smod+$dt['xoa_episode'];
						
					
					
							//----------Report Chap bị lỗi
						$db->query("select id from report_truyen where xuly=0");
						$dt['reporttruyen']=$db->num_rows();
						$k=	$dt['reporttruyen'];
						$admin=$admin+$k;
						$smod=$smod+$k;
						$uploader=$uploader+$k;
						
						
							//-----------BLOG HANDLE ---------------
								//---------CHUA DUYET TOPIC -------
						$db->query("select id from blog_post where status=0");
						$dt['blogduyet']=$db->num_rows();
						$admin=$admin+$dt['blogduyet'];	
						$smod=$smod+$dt['blogduyet'];
						$modforum=$dt['blogduyet'];
								// Comment post ---------------
										//---Hide Comment
						$db->query("select id from blog_comment where hide=1");
						$dt['bloghide']=$db->num_rows();
						$admin=$admin+$dt['bloghide'];	
						$smod=$smod+$dt['bloghide'];
						$modforum=$dt['bloghide'];
										//---Hide Comment
						$db->query("select id from blog_comment where report > 0");
						$dt['blogreport']=$db->num_rows();
						$admin=$admin+$dt['blogreport'];	
						$smod=$smod+$dt['blogreport'];
						$modforum=$dt['blogreport'];
						
						
						$db->close();
								//----- Truyen Chu-------
						$db=new Model2;
						$db->query("select id from truyen where duyet=0");
						$dt['truyen_duyet']=$db->num_rows();
						$admin=$admin+$dt['truyen_duyet'];
						$smod=$smod+$dt['truyen_duyet'];
						
						$db->query("select id from truyen where xoa=1");
						$dt['truyen_xoa']=$db->num_rows();
						$admin=$admin+$dt['truyen_xoa'];
						
						$db->query("select id from truyen_chuong where xoa=1");
						$dt['truyen_chuong_xoa']=$db->num_rows();
						$admin=$admin+$dt['truyen_chuong_xoa'];
						
						$db->query("select id from report_truyen where xuly=0");
						$dt['truyen_report']=$db->num_rows();
						$admin=$admin+$dt['truyen_report'];
						$smod=$smod+$dt['truyen_report'];
						
						$dt['uploader']=$k;
						$dt['smod']=$smod;
						$dt['admin']=$admin;
						
						$cache->save('static',$dt,120,'home');
						}
						?>
				
                    			<li class="dropdown">
						  <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">
							<i class="fa fa-exclamation-circle"></i> Xử Lý <span class="badge">
						<?php  if($_SESSION['user']['level']==5){ 
									echo $dt['uploader'];
								}else
								if($_SESSION['user']['level']==2){
									  echo $dt['smod'];
								}else{ 
								echo $dt['admin'];
								} ?>
                                </span>
						</a>
                        
                      <ul class="dropdown-menu">
                      <li role="presentation" class="dropdown-header">Manga</li>
                        
						<?php
							if($_SESSION['user']['level']==1){
								//----Admin boss --- ?>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=manga&opt=common&type=manga&ext=duyet">Duyệt Truyện <span class="badge"><?php echo $dt['duyet_anime'];?></span></a></li>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=manga&opt=common&type=manga&ext=xoa">Xóa Truyện <span class="badge"><?php echo $dt['xoa_anime'];?></span></a></li>
<li><a href="<?php echo HOME; ?>index.php?module=manage&act=manga&opt=common&type=chapter&ext=xoa">Xóa Chap <span class="badge"><?php echo $dt['xoa_episode']; ?></span></a></li>
<li><a href="<?php echo HOME; ?>index.php?module=manage&act=manga&opt=common&type=report&ext=xuly">Report Chap <span class="badge"><?php echo $dt['reporttruyen'];?></span></a></li>
                                <?php //End admin boss
							}
						?>	
                            
                      <?php
							if($_SESSION['user']['level']==2||$_SESSION['user']['level']==5){
								//----SMOD hoặc Uploader--- ?>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=manga&opt=common&type=manga&ext=duyet">Duyệt Truyện <span class="badge"><?php echo $dt['duyet_anime'];?></span></a></li>
<li><a href="<?php echo HOME; ?>index.php?module=manage&act=manga&opt=common&type=report&ext=xuly">Report Chap <span class="badge"><?php echo $dt['reporttruyen'];?></span></a></li>                                <?php //End admin boss
							}
						?>	   
                        
                           <!-- Section Manage Blog Post -->
                            <li role="presentation" class="divider"></li>
                            <li role="presentation" class="dropdown-header">Truyện Chữ</li>   
                            <?php
							if($_SESSION['user']['level']==1){
								//----Admin boss --- ?>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=truyen&opt=common&type=truyen&ext=duyet">Duyệt Truyện <span class="badge"><?php echo $dt['truyen_duyet'];?></span></a></li>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=truyen&opt=common&type=truyen&ext=xoa">Xóa Truyện <span class="badge"><?php echo $dt['truyen_xoa'];?></span></a></li>
<li><a href="<?php echo HOME; ?>index.php?module=manage&act=truyen&opt=common&type=chuong&ext=xoa">Xóa Chương <span class="badge"><?php echo $dt['truyen_chuong_xoa']; ?></span></a></li>
<li><a href="<?php echo HOME; ?>index.php?module=manage&act=truyen&opt=common&type=report&ext=xuly">Report <span class="badge"><?php echo $dt['truyen_report'];?></span></a></li>
                                <?php //End admin boss
							}
						?>	
                          <?php
							if($_SESSION['user']['level']==2){
								//----Admin boss --- ?>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=truyen&opt=common&type=truyen&ext=duyet">Duyệt Truyện <span class="badge"><?php echo $dt['truyen_duyet'];?></span></a></li>
<li><a href="<?php echo HOME; ?>index.php?module=manage&act=truyen&opt=common&type=report&ext=xuly">Report <span class="badge"><?php echo $dt['truyen_report'];?></span></a></li>
                                <?php //End admin boss
							}
						?>	
                            
                            
                            <!-- Section Manage Blog Post -->
                            <li role="presentation" class="divider"></li>
                            <li role="presentation" class="dropdown-header">Blog Moderator</li>  
                            
                            		<?php
							if($_SESSION['user']['level']==1){
								//----Admin boss --- ?>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=blog&opt=post&ext=duyet">Duyệt Topic <span class="badge"><?php echo $dt['blogduyet'];?></span></a></li>
<li><a href="<?php echo HOME;?>index.php?module=manage&act=blog&opt=post_comment&ext=hide">Hide Comment <span class="badge"><?php echo $dt['bloghide'];?></span></a></li>
<li><a href="<?php echo HOME; ?>index.php?module=manage&act=blog&opt=post_comment&ext=report">Report Comment <span class="badge"><?php echo $dt['blogreport']; ?></span></a></li>
                             <?php //End admin boss
							}
						?>	
                            
                            </ul>
					</li>
                          <?php
						  	}else{
				
			}
}

function common_get_image($str){
	if($str!=''){
		$html=str_get_html($str);
		$image=$html->find("img");
		
		$dl=false;
		if(count($image)>0){
		
			foreach($image as $vl){
				if(strpos($vl->src,"blogspot") !==false||strpos($vl->src,"manga24h") !==false){
				}else{
					$dl=true;
				}
			}
		}
		
		if($dl==true){
			$data="content=".$str;
			$url_remote="http://bk2.manga24h.com/index_tct.php";
			$res= mycurl($data,$url_remote);
			return $res;
		
		}else{
			return $str;
		}
	
	}

}

?>